

#include <gtk/gtk.h>

#include "menubar.h"
#include "window.h"
#include "keypad.h"
#include "codeview.h"
#include "memview.h"
#include "ioview.h"
#include "regflag.h"
#include "sourceview.h"
#include "fileops.h"
#include "page_state.h"
#include "statusbar.h"
#include "memfill.h"
#include "help.h"

/*##################### Static Functions ##################*/


/*################### Create item factory entry for menu ################*/
GtkItemFactoryEntry gsim_menubar_items[ ]  =
{
  { "/_File", NULL , 0 , 0 , "<Branch>" },
  { "/File/_New", "<control>N" , gsim_new_file , 0 ,  "<StockItem>" ,  GTK_STOCK_NEW  },
  { "/File/_Open", "<control>O",  gsim_open_file , 0 , "<StockItem>", GTK_STOCK_OPEN },
  { "/File/_Save", "<control>S", gsim_save_file , 0, "<StockItem>", GTK_STOCK_SAVE },
  { "/File/Save _As...", NULL,gsim_save_as_file, 0 , "<StockItem>", GTK_STOCK_SAVE_AS },
  { "/File/Save As _Text...", "<control>T",  gsim_save_text_file ,  0 , "<StockItem>", GTK_STOCK_SAVE },
  { "/File/Save A_ll...", NULL, gsim_save_all_files, 0, "<StockItem>", GTK_STOCK_SAVE_AS },
  { "/File/sep1", NULL, 0 , 0 , "<Separator>" },
  { "/File/_Close","<control>W",gsim_close_file, 0, "<StockItem>", GTK_STOCK_CLOSE },
  { "/File/Close All Files","<alt>D", gsim_close_all_files,       0, "<StockItem>", GTK_STOCK_CLOSE },
//  { "/File/sep2", NULL, 0, 0, "<Separator>" },
//  { "/File/_Print","<alt>P", gsim_print_file,  0, "<StockItem>", GTK_STOCK_PRINT },
  //{ "/File/Recent _Files",NULL, 0, 0, "<Branch>", },
  { "/File/sep3",  NULL,  0 ,  0 , "<Separator>" },
  { "/File/_Quit",  "<control>Q", quit_from_main , 0, "<StockItem>", GTK_STOCK_QUIT },
  { "/_Edit",  NULL, 0, 0, "<Branch>" },
  //{ "/Edit/Un_do",  "<control>Z"   , 0,0  ,"<StockItem>",GTK_STOCK_UNDO},
  //{ "/Edit/_Redo", "<control>R", 0,  0  ,"<StockItem>",GTK_STOCK_REDO},
  //{ "/Edit/sep1",  NULL, 0,  0, "<Separator>" },
  //{ "/Edit/C_ut", "<control>X", 0,  0  ,"<StockItem>",GTK_STOCK_CUT},
  //{ "/Edit/_Copy", "<control>C", 0,  0  ,"<StockItem>",GTK_STOCK_COPY},
  //{ "/Edit/_Paste", "<control>V", 0,  0  ,"<StockItem>",GTK_STOCK_PASTE},
  //{ "/Edit/sep2", NULL, 0, 0, "<Separator>" },
  { "/Edit/_Insert Row Before",   "<control>B", gsim_insert_row_before, 0,  "<StockItem>",GTK_STOCK_SORT_DESCENDING },
  { "/Edit/Insert Ro_w After",    "<control>F", gsim_insert_row_after, 0 ,"<StockItem>",GTK_STOCK_SORT_ASCENDING  },
  { "/Edit/Re_move Row",  "<alt>R", gsim_remove_row, 0  ,"<StockItem>",GTK_STOCK_REMOVE },
  { "/Edit/sep3",  NULL, 0, 0, "<Separator>" },
  { "/Edit/Edit Row", "<control>E", gsim_edit, 0, "<StockItem>", GTK_STOCK_CONVERT},
  { "/_View",	 NULL, 0, 0, "<Branch>" },
  { "/View/_KeyPad ", "<control>K",G_CALLBACK(show_hide_keypad),0,"<StockItem>",GSIM_STOCK_KEYPAD},
  { "/View/_Registers & Flags", "<control>G",show_hide_regflag,0,"<StockItem>",GSIM_STOCK_REG},
  { "/View/_Memory ", "<control>M",show_hide_memview,0,"<StockItem>",GSIM_STOCK_MEMORY},
  { "/View/_Ports", "<control>P",show_hide_ioview,0,"<StockItem>",GSIM_STOCK_PORT},
  { "/View/_Source Window", "<alt>S",G_CALLBACK(show_hide_sourceview),0,"<StockItem>",GSIM_STOCK_SOURCE},
  { "/_Memory",  NULL, 0,       0, "<Branch>" },
  { "/Memory/_Update Memory",  "<alt>U",gsim_update_memory, 0, "<StockItem>",GTK_STOCK_REFRESH },
  { "/Memory/_Memory Range ...", NULL, gsim_memview_change_range,       0,"<StockItem>",GTK_STOCK_INDEX},
  //{ "/_Memory/sep1",  NULL, 0,  0, "<Separator>" },
  //{ "/Memory/_Dump Memory (Binary)", NULL, 0,  0,"<StockItem>",GTK_STOCK_SAVE},
  //{ "/Memory/Load Dump (Binary)", NULL, 0,  0,"<StockItem>",GTK_STOCK_OPEN},
  //{ "/_Memory/sep2", NULL, 0, 0, "<Separator>" },
  //{ "/Memory/_Save Memory (Text)", NULL, 0,  0,"<StockItem>",GTK_STOCK_SAVE_AS},
  //{ "/Memory/_Print Memory Dump", NULL, 0,  0,"<StockItem>",GTK_STOCK_PRINT},
  //{ "/_Settings",  NULL, 0,  0,"<Branch>" },
  //{	  "/Settings/_Plugins ...", NULL, 0, 0,"<StockItem>",GTK_STOCK_INDEX},
  //{ "/Settings/sep1", NULL,  0,  0, "<Separator>" },
  //{ "/Settings/_Style ...", NULL, 0,  0,"<Branch>" },
  //{ "/Settings/Style .../S_ystem", NULL, 0,   0,"<RadioItem>" },
  //{ "/Settings/Style .../GSim85-_1 ", NULL, 0,  0,"/Settings/Style .../System" },
  //{ "/Settings/Style .../GSim85-_2", NULL, 0,  0,"/Settings/Style .../System" },
  //{ "/Settings/sep2",  NULL,0,  0, "<Separator>" },
  //{ "/Settings/Select _Colors ...", NULL, 0,  0,"<StockItem>",GTK_STOCK_SELECT_COLOR },
  //{ "/Settings/Select _Fonts ...", NULL, 0, 0,"<StockItem>",GTK_STOCK_SELECT_FONT },
  { "/_Tools", NULL, 0, 0,"<Branch>" },
  { "/_Help",  NULL,  0, 0, "<Branch>" },
  { "/Help/_Contents",  "<F>F1", gsim_contents, 0,"<StockItem>",GTK_STOCK_HELP },
  { "/Help/_About", NULL,gsim_help_about ,  0 ,"<StockItem>",GSIM_STOCK_ABOUT},
//  { "/Help/sep1", NULL,  0,  0, "<Separator>" },
 // { "/Help/_License", NULL,gsim_license, 0,"<StockItem>",GTK_STOCK_JUSTIFY_LEFT},
 // { "/Help/sep2",  NULL,  0,  0, "<Separator>" },
//  {"/Help/Report _Bugs",  NULL , gsim_report_bugs, 0 , "<Item>"},
//  {"/Help/_Getting Involved",  NULL , gsim_geting_involve, 0 , "<Item>"}
};


/*##################### Create the menubar ######################*/
GtkWidget *gsim_get_menubar( void )
{
	GtkAccelGroup *gsim_accel_group;
    GtkItemFactory *gsim_item_factory;
	GtkWidget *menubar;
	
	/*create main window's accelgroup*/
	gsim_accel_group = gtk_accel_group_new ();
    gtk_window_add_accel_group (GTK_WINDOW (gsim_appwindow), gsim_accel_group);
	g_object_unref( gsim_accel_group );

	/*create the menubar item factory and return menubar widget*/
	gsim_item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, 
												"<main>", gsim_accel_group);

	gtk_item_factory_create_items (gsim_item_factory, G_N_ELEMENTS ( gsim_menubar_items ),
                                     gsim_menubar_items , gsim_appwindow );
	menubar=gtk_item_factory_get_widget (gsim_item_factory, "<main>");
	gtk_widget_set_name(menubar,"menu");
	return menubar ;
}
